package com.clps.algorithm.chapter06.直方图最大矩形面积;

import javax.print.DocFlavor;

public class demo02 {
    public static void main(String[] args) {
        
    }
    
    public int largestRectangLeArea(int[] heights){
        if(heights.length ==0){
            return 0;
        }
        
        return  helper(heights,0,heights.length);
    }

    private int helper(int[] heights, int start, int end) {
        if(start == end){
            return  0;
        }

        if(start+1==end){
            return  heights[start];
        }

        int minindex = start;
        for (int i = start+1; i <end ; i++) {
            if(heights[i] < heights[minindex]){
                minindex = i;
            }
        }

        int area = (end-start) * heights[minindex];
        int left = helper(heights,start,minindex);
        int right = helper(heights, minindex + 1,minindex);


        area = Math.max(area,left);
        return  Math.max(area,right);
    }
}
